Add more tests for GdkRGBA parsing
authorMatthias Clasen <mclasen@redhat.com>
Mon, 9 Jan 2012 03:18:46 +0000 (22:18 -0500)
committerMatthias Clasen <mclasen@redhat.com>
Mon, 9 Jan 2012 05:31:20 +0000 (00:31 -0500)
These examples are taken from bug 667485.

gdk/tests/rgba.c

index d23bb96fe90af3b463df8cbd7bdb6f40a33ddafa..fa2da629bfe28545a3e2e9e857276d40a1118245 100644 (file)
@@ -49,6 +49,14 @@ test_color_parse (void)
   res = gdk_rgba_parse (&color, "#0080ff");
   g_assert (res);
   g_assert (gdk_rgba_equal (&color, &expected));
+
+  expected.red = 0.0;
+  expected.green = 0.0;
+  expected.blue = 0.0;
+  expected.alpha = 1.0;
+  res = gdk_rgba_parse (&color, "rgb(0,0,0)");
+  g_assert (res);
+  g_assert (gdk_rgba_equal (&color, &expected));
 }
 
 static void
@@ -107,12 +115,48 @@ test_color_copy (void)
   gdk_rgba_free (out);
 }
 
+static void
+test_color_parse_nonsense (void)
+{
+  GdkRGBA color;
+  gboolean res;
+
+  g_test_bug ("667485");
+
+  res = gdk_rgba_parse (&color, "rgb(,,)");
+  g_assert (!res);
+
+  res = gdk_rgba_parse (&color, "rgb(%,%,%)");
+  g_assert (!res);
+
+  res = gdk_rgba_parse (&color, "rgb(nan,nan,nan)");
+  g_assert (!res);
+
+  res = gdk_rgba_parse (&color, "rgb(inf,inf,inf)");
+  g_assert (!res);
+
+  res = gdk_rgba_parse (&color, "rgb(1p12,0,0)");
+  g_assert (!res);
+
+  res = gdk_rgba_parse (&color, "rgb(5d1%,1,1)");
+  g_assert (!res);
+
+  res = gdk_rgba_parse (&color, "rgb(0,0,0)moo");
+  g_assert (!res);
+
+  res = gdk_rgba_parse (&color, "rgb(0,0,0)  moo");
+  g_assert (!res);
+}
+
 int
 main (int argc, char *argv[])
 {
         g_test_init (&argc, &argv, NULL);
 
+        g_test_bug_base ("http://bugzilla.gnome.org");
+
         g_test_add_func ("/rgba/parse", test_color_parse);
+        g_test_add_func ("/rgba/parse/nonsense", test_color_parse_nonsense);
         g_test_add_func ("/rgba/to-string", test_color_to_string);
         g_test_add_func ("/rgba/copy", test_color_copy);